﻿using Facebook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SoccerEvaluator.WebSite
{
    /// <summary>
    /// 
    /// </summary>
    public partial class GroupList : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        protected string siteUrl;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.siteUrl = Page.ResolveUrl("~");

            //this.siteUrl = @"localhost:51696/";

            if (!this.IsPostBack)
            {
                if (this.Request.QueryString["message"] != null)
                {
                    string key = this.Request.QueryString["message"];

                    string msg = (string)HttpContext.GetGlobalResourceObject("Resource", key);

                    string script = string.Format("alert('{0}')", msg);

                    ClientScript.RegisterClientScriptBlock(typeof(string), "message", script, true);
                }

                /*
                try
                {

                    Session["AccessToken"] = Request["accessToken"]; 

                    var accessToken = Session["AccessToken"].ToString();
                    var client = new FacebookClient(accessToken);
                    dynamic result = client.Get("me", new { fields = "name,id" });
                    string name = result.name;
                    string id = result.id;

                    if (id == null || id.Length == 0)
                    {
                        Response.Redirect("default.aspx");
                    }
                }
                catch 
                {
                    Response.Redirect("default.aspx");
                }
                  */
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string GetUrl()
        {
            string url = Request.Url.AbsolutePath;

            var segments = Request.Url.Segments;
            var len = segments.Length;

            for (int i = 1; i <= 2; i++)
            {
                var lastSegment = Request.Url.Segments[len - i];
                var subStringIndex = url.LastIndexOf(lastSegment);
                url = url.Remove(subStringIndex);
            }

            return url;
        }
    }
}